package com.ktjy.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class TimeSpanAspect {
    private static final Logger log= LoggerFactory.getLogger(TimeSpanAspect.class);

    public Object around(ProceedingJoinPoint pjp) throws Throwable {
        log.info("【环绕增强-前置】 记录{}方法执行的开始时间.", pjp.getSignature().getName());
        long start = System.currentTimeMillis();
        try {
            Object result = pjp.proceed();
            log.info("【环绕增强-后置】{}方法执行结果为{}.", pjp.getSignature().getName(), System.currentTimeMillis(),start);
            return result;
        }catch (Throwable e){
            log.info("【环绕增强-异常】{}方法执行异常信息为{}.", pjp.getSignature().getName(), System.currentTimeMillis(),start);
            throw e;
        }finally {
            long endTime = System.currentTimeMillis();
            log.info("【环绕增强-最终】记录{}方法执行的结束时间，并计算耗时为{}ms.",pjp.getSignature().getName(), (endTime-start));
        }

    }
}
